/**
 * 本代码主要进行Number类型数据的格式化处理，系统会在格式化输出时，先判断小数点后两位是否均为0，如果是，则直接返回整数部分，否则返回对应两位小数 
 * 
 * @author Harrison
 */ 
package com.easidea.tim.flex.util
{
	import mx.formatters.NumberFormatter;

	public class TimNumberFormatter extends NumberFormatter
	{
		private static var _instance:TimNumberFormatter ;
		
		public function TimNumberFormatter()
		{
			super.precision = 2;
		}
		
		public static function getInstance():TimNumberFormatter {
			if(!_instance){
				_instance = new TimNumberFormatter();
			}
			return _instance
		}
		
		/**
		 * 格式化
		 * 
		 */
		override public function format(number:Object):String {
			var rtnStr:String = "";
			if(number is Number){
				var numStr:String = super.format(number);
				if(numStr != "" && numStr.length > 0){
					var intIndex:int = numStr.indexOf(".00"); 
					if( intIndex > 0){
						// 整数
						rtnStr = numStr.substring(0,intIndex);
					}else{
						// 非整数
						rtnStr = numStr;
					}
				}
			}else if ( number is String){
				rtnStr = number as String;
			}
			return rtnStr;
		}
	}
}